﻿using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using GdNet.Core.Assistants;
using GdNet.Core.Domain.Metadata;

namespace GdNet.Integrations.NHibernate.Assistants
{
    public static class MappingAssistant
    {
        public static string GetForeignKeyColumn<T>(Expression<Func<T>> property)
        {
            string propertyName = ObjectAssistant.GetPropertyName(property);
            return string.Concat(propertyName, EntityMeta.Id);
        }

        public static string GetForeignKeyColumn<T>()
        {
            string idProperty = ObjectAssistant.GetPropertyName(() => EntityMeta.Id);
            return string.Concat(typeof(T).Name, idProperty);
        }

        public static string GetTableStrongName(Type type)
        {
            List<string> sqlObjectNames = new List<string>
            {
                "user",
            };

            if (sqlObjectNames.Contains(type.Name.ToLower()))
            {
                return string.Format("[{0}]", type.Name);
            }

            return type.Name;
        }
    }
}
